package com.bawei.exam57.utils

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitUtils {
    fun getRetrofit(): Retrofit {
        return Retrofit.Builder()
            .baseUrl("http://10.161.9.80:7456")
            .addConverterFactory(GsonConverterFactory.create())
            .client(OkHttpClient.Builder()
                .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .addInterceptor { chain ->
                    val request = chain.request()
                    val builder = request.newBuilder()
                    val s = SPUtils.getInstance().getString("token")
                    if (s.isNotEmpty()) {
                        builder.addHeader("Authori-zation", s)
                    }
                    chain.proceed(builder.build())
                }
                .build())
            .build()
    }
}